package cn.usts.edu.lesson02;

/**
 * 并发会导致对数据的访问有问题
 * */
public class ThreadProblem implements Runnable{
    private int tickets=10;

    @Override

    public void run() {
        String threadName = Thread.currentThread().getName(); // 获取当前线程的名字
        while (true){
            if (tickets<=0){
                break;
            }
            System.out.println("【"+threadName+"】"+tickets--);

        }
    }

    public static void main(String[] args) {
        ThreadProblem ticket = new ThreadProblem();
        new Thread(ticket,"小明").start();
        new Thread(ticket,"小红").start();
        new Thread(ticket,"黄牛").start();
    }


}
